//package com.lucifer.cloud.boot.blog.ai.model.classification;
//
//import org.deeplearning4j.nn.conf.MultiLayerConfiguration;
//import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
//import org.deeplearning4j.nn.conf.inputs.InputType;
//import org.deeplearning4j.nn.conf.layers.ConvolutionLayer;
//import org.deeplearning4j.nn.conf.layers.DenseLayer;
//import org.deeplearning4j.nn.conf.layers.OutputLayer;
//import org.deeplearning4j.nn.conf.layers.SubsamplingLayer;
//import org.deeplearning4j.nn.multilayer.MultiLayerNetwork;
//import org.nd4j.linalg.activations.Activation;
//import org.nd4j.linalg.learning.config.Adam;
//import org.nd4j.linalg.lossfunctions.LossFunctions;
//
///**
// * @author lucifer
// * @date 2024/11/28 13:51
// */
//public class CNNModel {
//
//    public static MultiLayerNetwork buildModel(int numClasses) {
//        NeuralNetConfiguration.ListBuilder modelBuilder = new NeuralNetConfiguration.Builder()
//                .updater(new Adam(0.001)) // 优化器
//                .list();
//
//        // 第一层卷积层
//        modelBuilder.layer(new ConvolutionLayer.Builder(5, 5)
//                .nIn(3) // 输入图像的通道数
//                .nOut(32) // 输出通道数
//                .activation(Activation.RELU)
//                .build());
//
//        // 添加池化层
//        modelBuilder.layer(new SubsamplingLayer.Builder()
//                .poolingType(SubsamplingLayer.PoolingType.MAX)
//                .kernelSize(2, 2)
//                .stride(2, 2)
//                .build());
//
//        // 添加全连接层
//        modelBuilder.layer(new DenseLayer.Builder().nOut(128).activation(Activation.RELU).build());
//
//        // 输出层
//        modelBuilder.layer(new OutputLayer.Builder(LossFunctions.LossFunction.NEGATIVELOGLIKELIHOOD)
//                .nOut(numClasses) // 输出类别数
//                .activation(Activation.SOFTMAX)
//                .build());
//
//        // 配置模型
//        MultiLayerConfiguration conf = modelBuilder.setInputType(InputType.convolutionalFlat(Constant.height, Constant.width, Constant.depth)).build();
//        MultiLayerNetwork model = new MultiLayerNetwork(conf);
//        model.init();
//        return model;
//    }
//}
